const Mock = require('mockjs')

const Random = Mock.Random
const questionList = require('./questionList')
const {query} = require("koa/lib/request");
module.exports = [
  {
    // 获取单个问卷信息
    url: '/api/question/:id',
    method: 'get',
    response() {
      return {
        errno: 0,
        data: {
          id: Random.id(),
          title: Random.ctitle(),
          componentList: [
            {
              fe_id: Random.id(),
              type: 'questionTitle',//组件类型，不能重复，前后端统一
              title: '标题',
              isHidden: false,
              isLocked: false,
              props: {
                text: '一行标题11',
                level: 1,
                isCenter: true
              }
            },
            {
              fe_id: Random.id(),
              type: 'questionInput',
              title: '输入框',
              isHidden: false,
              isLocked: false,
              props: {
                title: '问卷标题2134',
                placeholder: '请输入...'
              }
            },
            {
              fe_id: Random.id(),
              type: 'questionRadio',
              title: '单选',
              isHidden: false,
              isLocked: false,
              props: {
                title: '单选标题',
                isVertical: false,
                options: [
                  {value: 'item1', text: '选项1'},
                  {value: 'item2', text: '选项2'},
                  {value: 'item3', text: '选项3'},
                ],
                value: ''
              }
            }
          ]
        }
      }
    }
  },
  {
    // 创建问卷
    url: '/api/question', isLocked: false,

    method: 'post',
    response() {
      return {
        errno: 0,
        data: {
          id: Random.id(),
        }
      }
    }
  },
  {
    // 获取（查询）问卷列表
    url: '/api/question',
    method: 'get',
    response(ctx) {
      const {url = '', query = {}} = ctx
      const isDeleted = ctx.url.indexOf('isDeleted=true') >= 0
      const isStar = ctx.url.indexOf('isStar=true') >= 0
      console.log('ctx', ctx.query)
      const pageSize = parseInt(query.pageSize) || 10
      const total = 100
      return {
        errno: 0,
        data: {
          total: 100,
          list: questionList({len: pageSize, isDeleted, isStar, pageSize})
        }
      }
    }
  },
  {
    // 更新问卷信息
    url: '/api/question/:id',
    method: 'patch',
    response() {
      return {
        errno: 0
      }
    }
  },
  {
    // 更新问卷信息
    url: '/api/question/duplicate/:id',
    method: 'post',
    response() {
      return {
        errno: 0,
        data: {
          id: Random.id()
        }
      }
    }
  },
  {
    // 删除问卷
    url: '/api/question',
    method: 'delete',
    response() {
      return {
        errno: 0
      }
    }
  }
]
